* Iris Arbogast (irisarbogast@gmail.com)
* 8/29/2023
/* This program runs regressions for ACS data and checks the correlation between CMS and ACS at the bottom*/


*****************
* Table 5: Impact of policy changes on child Medicaid enrollment in ACS
*****************
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
est clear

svyset statefip [pweight=perwt]

* Benchmark
eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip

* No state-year vars
eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs noncitp engtbp i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc i.year i.statefip 

* With 2020
use Data/Clean/CleanedACSData.dta, clear
svyset statefip [pweight=perwt]

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip 

* Trump Administration
drop if year == 2020

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden i.public_charge_2017##i.hispanic L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc  noncitp engtbp i.year i.statefip 

* Public charge

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden i.public_charge_2019##i.hispanic L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip


esttab using "Output/Tables/Table5.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 star(* 0.05 ** 0.01) ///
  drop(*.year *.statefip) ///
  mtitle("Benchmark" "No state-year vars" "With 2020" "Trump Administration" "Public Charge") ///
  rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L2_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201  L_Work_Reqs Work_Reqs) ///
 order(Adminburden 1.hispanic 1.public_charge_2017#1.hispanic 1.public_charge_2019#1.hispanic) nobaselevel 

 
 
 
*****************
* Appendix Table 6: Impact of lagged policy changes on child Medicaid enrollment in ACS data, 2010-2019
*****************
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
svyset statefip [pweight=perwt]
est clear

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.sex i.educ_ag i.age_bucket c.ftotinc noncitp engtbp  i.year i.statefip

eststo: svy, subpop(if age < 19): reg Medicaid_covered L2_Adminburden L2_new_redetpause L2_MedicaidExpansion L2_cutoffmax L2_Premlevel_201 L2_Work_Reqs L2_pov L2_ur L2_GSP i.hispanic i.race_bucket i.sex i.educ_ag i.age_bucket noncitp engtbp  c.ftotinc i.year i.statefip 

eststo: svy, subpop(if age < 19): reg Medicaid_covered L3_Adminburden L3_new_redetpause L3_MedicaidExpansion L3_cutoffmax L3_Premlevel_201 L3_Work_Reqs L3_pov L3_ur L3_GSP i.hispanic i.race_bucket i.sex i.educ_ag i.age_bucket noncitp engtbp  c.ftotinc i.year i.statefip

eststo: svy, subpop(if age < 19):  reg Medicaid_covered L4_Adminburden L4_new_redetpause L4_MedicaidExpansion L4_cutoffmax L4_Premlevel_201 L4_Work_Reqs L4_pov L4_ur L4_GSP i.hispanic i.race_bucket i.sex noncitp engtbp i.educ_ag i.age_bucket c.ftotinc i.year i.statefip 

eststo: svy, subpop(if age < 19):  reg Medicaid_covered L5_Adminburden L5_new_redetpause L5_MedicaidExpansion L5_cutoffmax L5_Premlevel_201 L5_Work_Reqs L5_pov L5_ur L5_GSP i.hispanic i.race_bucket noncitp engtbp  i.sex i.educ_ag i.age_bucket c.ftotinc i.year i.statefip 


 esttab using "Output/Tables/Ap_Table6.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 star(* 0.05 ** 0.01) ///
 drop(*.year *.statefip *.race_bucket *.sex *.age_bucket ftotinc *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("Benchmark" "2 year lag" "3 year lag" "4 year lag" "5 year lag") ///
  rename(L_Adminburden Adminburden L2_Adminburden Adminburden L3_Adminburden Adminburden L4_Adminburden Adminburden L5_Adminburden Adminburden L_new_redetpause new_redetpause L2_new_redetpause new_redetpause L3_new_redetpause new_redetpause L4_new_redetpause new_redetpause L5_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L2_MedicaidExpansion MedicaidExpansion L3_MedicaidExpansion MedicaidExpansion L4_MedicaidExpansion MedicaidExpansion L5_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L2_cutoffmax cutoffmax L3_cutoffmax cutoffmax L4_cutoffmax cutoffmax L5_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L2_Premlevel_201 Premlevel_201 L3_Premlevel_201 Premlevel_201 L4_Premlevel_201 Premlevel_201 L5_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs L2_Work_Reqs Work_Reqs L3_Work_Reqs Work_Reqs L4_Work_Reqs Work_Reqs L5_Work_Reqs Work_Reqs L_pov pov L2_pov pov L3_pov pov L4_pov pov L5_pov pov L_GSP GSP L2_GSP GSP L3_GSP GSP L4_GSP GSP L5_GSP GSP L_ur ur L2_ur ur L3_ur ur L4_ur ur L5_ur ur) ///
 order(Adminburden) nobaselevel 


 
 
*****************
* Table 6: Impact of policy changes on child Medicaid and CHIP enrollment by demographic group in ACS data, 2010-2019
*****************
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
svyset statefip [pweight=perwt]
est clear

 * race/ethnicity group
foreach demgroup in white black raceother {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.sex i.age_bucket noncitp engtbp c.ftotinc i.year i.statefip 

}

foreach demgroup in hispanic nothispanic {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.educ_ag i.race_bucket i.sex i.age_bucket noncitp engtbp c.ftotinc i.year i.statefip 

}


esttab using "Output/Tables/Table6_PanelA.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 star(* 0.05 ** 0.01) ///
 drop(*.year *.statefip *.race_bucket *.sex *.age_bucket ftotinc *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("White" "Black" "Other Race" "Hispanic"  "Not Hispanic") ///
 order(Adminburden) nobaselevel ///
 rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs) 
 
 
* Income group 

 
est clear


foreach demgroup in all {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.race_bucket c.ftotinc noncitp engtbp i.sex i.age_bucket i.year i.statefip 

}



foreach demgroup in  fpl100 fpl200 fpl2to400 fpl400 {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.race_bucket noncitp engtbp i.sex i.age_bucket i.year i.statefip 

}


esttab using "Output/Tables/Table6_PanelB.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
 star(* 0.05 ** 0.01) ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 drop(*.year *.statefip *.race_bucket *.sex *.age_bucket *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("All" "<100% FPL" "100-200% FPL"  "200-400% FPL" ">400% FPL") ///
 order(Adminburden) nobaselevel ///
 rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs) 
 
 
* Parents Group
est clear


foreach demgroup in noyr4clgp yr4clgp  {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic noncitp engtbp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}

foreach demgroup in noncitp citp {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag engtbp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}


foreach demgroup in  engtbp engnotbp {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag noncitp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}



esttab using "Output/Tables/Table6_PanelC.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
 star(* 0.05 ** 0.01) ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 drop(*.year *.statefip *.race_bucket *.sex *.age_bucket ftotinc *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("Without 4-year College Parents" "4-year College Parent" "Non-Citizen Parent" "Citizen Parents" "Weak English Parent" "Without Weak English Parent") ///
 order(Adminburden) nobaselevel ///
 rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs) 
 
* Age Group Group
est clear


foreach demgroup in infants Ageoneto5 Agesixto12 Age13up no18yr  {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag noncitp engtbp i.race_bucket i.sex c.ftotinc i.year i.statefip 

}

esttab using "Output/Tables/Table6_PanelD.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
  stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
 star(* 0.05 ** 0.01) ///
 drop(*.year *.statefip *.race_bucket *.sex ftotinc *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("Infants" "Age 1 - 5" "Age 6 - 12" "Age 13+" "Age 0 - 17") ///
 order(Adminburden) nobaselevel ///
 rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs) 
 

 
*****************
* Appendix Table 7: Missing
*****************
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
svyset statefip [pweight=perwt]
est clear


foreach demgroup in all {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.race_bucket c.ftotinc noncitp engtbp i.sex i.age_bucket i.year i.statefip 

}


foreach demgroup in white black raceother {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.sex i.age_bucket noncitp engtbp c.ftotinc i.year i.statefip 

}

foreach demgroup in hispanic nothispanic {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.educ_ag i.race_bucket i.sex i.age_bucket noncitp engtbp c.ftotinc i.year i.statefip 

}



foreach demgroup in fpl100 fpl200 fpl2to400 fpl400 {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag i.race_bucket noncitp engtbp i.sex i.age_bucket i.year i.statefip 

}


foreach demgroup in noyr4clgp yr4clgp  {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic noncitp engtbp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}

foreach demgroup in noncitp citp {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag engtbp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}


foreach demgroup in  engtbp engnotbp {

eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag noncitp i.race_bucket i.sex i.age_bucket c.ftotinc i.year i.statefip 

}


 foreach demgroup in infants Ageoneto5 Agesixto12 Age13up no18yr  {

 eststo: svy, subpop(if age < 19 & `demgroup' == 1): reg Any_Covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.educ_ag noncitp engtbp i.race_bucket i.sex c.ftotinc i.year i.statefip 

 }



 esttab using "Output/Tables/Ap_Table7.csv", replace  ///
  b(4) se(4) label scalar("r2_w  Within R2") ///
   stats(N_sub, fmt("%9.0f") labels("N person-years, unweighted")) ///
  star(* 0.05 ** 0.01) ///
 drop(*.year *.statefip *.race_bucket *.sex *.age_bucket ftotinc *.hispanic *.educ_ag noncitp engtbp) ///
  mtitle("All" "White" "Black" "Other Race" "Hispanic"  "Not Hispanic" "<100% FPL" "100-200% FPL"  "200-400% FPL" ">400% FPL" "Without 4-year College Parents" "4-year College Parent" "Non-Citizen Parent" "Citizen Parents" "Weak English Parent" "Without Weak English Parent" "Infants" "Age 1 - 5" "Age 6 - 12" "Age 13+" "Age 0 - 17") ///
 order(Adminburden) nobaselevel ///
 rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201 L_Work_Reqs Work_Reqs) 



*****************
* Footnote 20 regressions
*****************
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
est clear
svyset statefip [pweight=perwt]


eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip

drop if year == 2019

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip

drop if year == 2018

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip


drop if year == 2017

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip


use Data/Clean/CleanedACSData.dta, clear

keep if year >= 2014 

svyset statefip [pweight=perwt]

eststo: svy, subpop(if age < 19): reg Medicaid_covered L_Adminburden L_new_redetpause L_MedicaidExpansion L_cutoffmax L_Premlevel_201 L_Work_Reqs L_pov L_ur L_GSP i.hispanic i.race_bucket i.educ_ag i.sex i.age_bucket c.ftotinc noncitp engtbp i.year i.statefip


esttab using "Output/Tables/Footnote20.csv", replace  ///
 b(4) se(4) label scalar("r2_w  Within R2") ///
  stats(N_subpop  N_sub, fmt("%9.0f") labels("Weighted Sample Size" "Observation Count")) ///
 star(* 0.05 ** 0.01) ///
  drop(*.year *.statefip) ///
  mtitle("Benchmark" "2010 - 2018" "2010 - 2017" "2010 - 2016" "2014 - 2020") ///
  rename(L_Adminburden Adminburden L_new_redetpause new_redetpause L_MedicaidExpansion MedicaidExpansion L_cutoffmax cutoffmax L2_cutoffmax cutoffmax L_Premlevel_201 Premlevel_201  L_Work_Reqs Work_Reqs) ///
 order(Adminburden 1.hispanic 1.public_charge_2017#1.noncitp 1.public_charge_2019#1.noncitp) nobaselevel 
 
 
*****************
* Calculate means
*****************
* 2014 - 2020
use Data/Clean/CleanedACSData.dta, clear
svyset statefip [pweight=perwt]
est clear
drop if year < 2014
svy, subpop(if age < 19): mean Medicaid_covered


* 2010 - 2019
use Data/Clean/CleanedACSData.dta, clear
drop if year == 2020
svyset statefip [pweight=perwt]
est clear
tab year
svy, subpop(if age < 19): mean Medicaid_covered


* 2010 - 2019 Any coverage 
use Data/Clean/CleanedACSData.dta, clear
svyset statefip [pweight=perwt]
drop if year == 2020
est clear
svy, subpop(if age < 19): mean Any_Covered



*******************
* Look at correlations between ACS and CMS data
*******************
* First, create state-level series for the ACS
use Data/Clean/CleanedACSData.dta, clear
keep if age < 19
collapse (sum) perwt, by(year statefip Medicaid)
reshape wide perwt, i(statefip year) j(Medicaid)
rename perwt1 No
rename perwt2 Yes
gen totalchildren = Yes + No
gen ACSenrollrate = Yes/totalchildren
drop No Yes 
sort statefip year
rename statefip st

* Get statefips from a separate file to make the merging work
merge m:1 st using Data/statefips.dta
rename stname sname
drop _merge
save Data/Clean/ACS_enrollrate.dta, replace


* merge in CMS data
use Data/Clean/Cleaned_Policy_Data.dta, clear
duplicates drop
collapse (mean) mchiprate, by(year st stusps)
merge 1:1 st year using Data/Clean/ACS_enrollrate.dta

* Clean up data to get the correct sample
drop if inlist(year,2008, 2009, 2010,2011, 2012, 2013, 2020)
drop if st==11

correlate ACSenrollrate mchiprate


